<%@ taglib uri="/WEB-INF/tld/struts-html.tld"   prefix="html"%>

<%@page import="java.util.List,org.tigris.atlas.quizme.client.form.AnswerForm,org.tigris.atlas.quizme.transfer.Quiz,java.util.Set,org.tigris.atlas.quizme.transfer.Answer,org.tigris.atlas.quizme.transfer.Question,org.tigris.atlas.quizme.client.utils.Constants"%>
<div class="tab-page">
		<div id="subPages" class="disabled link-row">
			<table class="wide-table">
				<tr>
					<td width="780" height="10">
							<H2>Quiz Results</H2>
					</td>
				</tr>
			</table>
		</div>
		
	<table cellpadding="0" cellspacing="0" border="0">
	<tr>
   <td colspan="2">
   <%
   		Quiz quiz = ((Quiz)request.getSession().getAttribute(Constants.QUIZ_KEY));
   		List userAnswers = (List)request.getSession().getAttribute(Constants.ANSWERS_KEY);
   		java.util.Date start = quiz.getTimeStarted();
   		java.util.Date end = quiz.getTimeEnded();
   		long totalTime = end.getTime() - start.getTime();
   		java.util.Date totalTimeObject = new java.util.Date(totalTime);
   		long timePerQuestion = totalTime/quiz.getNumQuestions().intValue();
   		java.util.Date timePerObject = new java.util.Date(timePerQuestion);
   		java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("mm:ss");
	%>

	&nbsp;<B>Score:</B><font color="red"> <%= quiz.getNumCorrect() %> out of <%= quiz.getNumQuestions() %></font><BR>
	&nbsp;<B>Total Time:</B><font color="red"> <%= format.format(totalTimeObject) %></font><BR>
	&nbsp;<B>Time Per Question:</B><font color="red"> <%= format.format(timePerObject) %></font><BR>
	
	<form name="QuestionForm" action="<html:rewrite page='/pages/quizPage.jsp'/>">
	<table border="1px">
	<% 

		for(int i=0; i < userAnswers.size(); i++){
			AnswerForm answer = (AnswerForm)userAnswers.get(i);
	%>
	<tr>
		<td>
		<%
			if("true".equals(answer.getIsCorrect())){
		%>
		<img src="<html:rewrite page='/images/feedback-success.gif'/>">
		<%
			}else{
		%>
		<img src="<html:rewrite page='/images/feedback-error.gif'/>">
		<%} %>
		</td>
		<td><%=i+1%></td>
		<td><a href="<%= request.getContextPath() %>/answerDetail.do?index=<%=i%>">details</a></td>
		<td><%= answer.getQuestion() %></td>
	</tr>
	<% } %>
	</table>
	</form>
	<table width="780" border="0">
		<tr>
			<td colspan="2">
				<button name="save" id="5" enabledMode="" accesskey="N"
					class="imageButton" type="button"
					onclick="javascript:document.QuestionForm.submit()" onmouseout="javascript:className='imageButton';" onmouseover="javascript:className='activeImageButton';" >
					<IMG src="<html:rewrite page='/images/goto.gif'/>" alt="New Quiz"><IMG src="<html:rewrite page='/images/space.gif'/>" height="20" width="1">
					<span class="underline">N</span>ew Quiz
				</button>
			</td>
		</tr>
	</table>
<BR>
</td>
</tr>
</table>